//
//  WYHelpVC.m
//  私訂生活
//
//  Created by 王琰 on 15/1/14.
//  Copyright (c) 2015年 王琰. All rights reserved.
//

#import "WYHelpVC.h"

@interface WYHelpVC ()<UIScrollViewDelegate>
{
    //滑动提示
//    UIPageControl *_pageControl;
}
@end

@implementation WYHelpVC
- (void)viewWillAppear:(BOOL)animated
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    //根据屏幕尺寸放入3张图片
    UIScrollView *s = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WYMWITH, WYMHEIGHT)];
    for (int i = 1; i < 6; i++) {
        UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(WYMWITH*(i-1), 0, s.frame.size.width, s.frame.size.height)];
        if (WYMHEIGHT == 480.0) {
            imv.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d",@"help_small_",i]];
        }else{
            imv.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d",@"help_big_",i]];
        }
        if (i == 3) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(0, 0, 120, 35);
            btn.center = CGPointMake(WYMWITH/2, WYMHEIGHT - 75*AUTOY);
            [btn setTitle:@"开启夺宝之旅" forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside];
            btn.backgroundColor = QBB_RED_COLOR;
            btn.layer.cornerRadius = 2;
            btn.layer.masksToBounds = YES;
            [imv addSubview:btn];
            imv.userInteractionEnabled = YES;
            
            UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(0, WYMHEIGHT - 30, WYMWITH, 20)];
            l.textAlignment = NSTextAlignmentCenter;
            l.font = [UIFont systemFontOfSize:14];
            l.textColor = [UIColor blackColor];
            l.text = @"所有商品抽奖活动与苹果公司(Apple Inc.)无关";
            [imv addSubview:l];
        }
        [s addSubview:imv];
    }
    s.contentSize = CGSizeMake(WYMWITH*3, 0);
    s.pagingEnabled = YES;
    s.delegate = self;
    s.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:s];
    
//    _pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 0, 120, 20)];
//    _pageControl.center = CGPointMake(WYMWITH/2, CGRectGetMaxY(s.frame)-25-20/2);
//    _pageControl.numberOfPages = 5;
//
//    [self.view addSubview:_pageControl];
}
- (void)btnOnClick:(UIButton *)btn
{
//    if ([self.delegate respondsToSelector:@selector(wyHelpHC:buttonClick:)]){
//        [self.delegate wyHelpHC:self buttonClick:btn];
//    }
    
    [UIView animateKeyframesWithDuration:1.0 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
        
        [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:1/2.0 animations:^{
            self.view.alpha = 0.5f;
            self.view.transform = CGAffineTransformMakeScale(1.5, 1.5);
        }];
//        if ([self.delegate respondsToSelector:@selector(wyHelpHC:buttonClick:)]){
//            [self.delegate wyHelpHC:self buttonClick:btn];
//        }
        [UIView addKeyframeWithRelativeStartTime:1/2.0 relativeDuration:1/2.0 animations:^{
            self.view.alpha = 0.0f;
            self.view.transform = CGAffineTransformMakeScale(2.0f, 2.0f);
            
        }];
        
    } completion:^(BOOL finished) {
        if ([self.delegate respondsToSelector:@selector(wyHelpHC:buttonClick:)]){
            [self.delegate wyHelpHC:self buttonClick:btn];
        }
        
    }];
    
//    [UIView animateWithDuration:0.5 animations:^{
//        self.view.alpha = 0.2;
//        self.view.transform = CGAffineTransformMakeScale(1.5, 1.5);
//    } completion:^(BOOL finished) {
////        [self.navigationController popViewControllerAnimated:NO];
//        //通知代理按钮点击了
//        if ([self.delegate respondsToSelector:@selector(wyHelpHC:buttonClick:)]){
//            [self.delegate wyHelpHC:self buttonClick:btn];
//        }
//    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    if (scrollView.contentOffset.x - 50>(scrollView.contentSize.width - WYMWITH)) {
//        [UIView animateWithDuration:.45 animations:^{
//            self.view.alpha = 0;
//        } completion:^(BOOL finished) {
//            [self.navigationController popViewControllerAnimated:NO];
//        }];
//        
//    }
//}
////管理页面显示指示器
//- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
//{
//   
//        NSInteger i = scrollView.contentOffset.x/WYMWITH;
//        _pageControl.currentPage = i;
//}
//隐藏状态栏
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
@end
